<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合作伙伴列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse hidden">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="clickChoosePartner()">
                    <i class="fa fa-add"></i> 新增合作伙伴
                </a>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var type=[[${type}]];//1隐藏（新增按钮 删除按钮） 0合作伙伴增删改查维护

        var prefix = ctx + "partner/tenementInfo";

        if(type==1){
            $("#toolbar").addClass("hidden");
        }
        $(function() {
            let options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "合作伙伴",
                sortName: "partnerId",
                sortOrder:"desc",
                columns: [{
                    radio: true
                },
                    {
                        field: 'id',
                        title: 'id',
                        visible: false
                    },
                    {
                        field: 'deptId',
                        title: '部门id',
                        visible: false
                    },
                    {
                        field: 'deptName',
                        title: '企业名称'
                    },
                    {
                        field: 'code',
                        title: '税号'
                    },
                    {
                        field: 'leader',
                        title: '负责人'
                    },
                    {
                        field: 'phone',
                        title: '联系电话'
                    },
                    {
                        field: 'email',
                        title: '邮箱'
                    },

                    {
                        field: 'address',
                        title: '企业地址'
                    },
                {
                    title: '操作',
                    align: 'center',
                    visible: type==1?false:true,
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function clickChoosePartner(){
           let url=ctx + "partner/dept?operateFlag=1";
            $.modal.open("选择合作伙伴",url,1200,$(window).height() - 50,function (index,layero){
                var wind = layero.find('iframe')[0].contentWindow;
                var rowsjSON = wind.getSelections();
                if(rowsjSON.length>0){
                    $.modal.confirm("确认保存？",function (){
                        var data = {"params[list]":rowsjSON,};
                        $.operate.save(ctx+"partner/tenementInfo/add", data,function (result){
                            if (result.code == web_status.SUCCESS) {
                                $.modal.msg("入库成功！");
                                $.modal.close(index);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                        });
                    });
                }
            });
        }
        function getSelectionRadio() {
           var rows=  $('#bootstrap-table').bootstrapTable('getSelections');
            return rows;
        }

    </script>
</body>
</html>
